package cn.picclife.mwx.manager.util;

import org.apache.log4j.Logger;

public class LogUtil {
	
	private static Logger logger = Logger.getLogger(LogUtil.class);
	
	public static void info (String message){
		logger.info(getMessage(message));
	}
	
	public static void debug (String message){
		logger.debug(message);
	}
	
	public static void warn (String message){
		logger.warn(getMessage(message));
	}
	
	public static void error (String message){
		logger.error(getMessage(message));
	}
	
	public static void error (String message, Throwable t){
		logger.error(getMessage(message), t);
	}
	
	private static String getMessage(String msg){
		String className = "";
		StackTraceElement[] exception = Thread.currentThread().getStackTrace();
		for (StackTraceElement ste : exception) {
			className = ste.toString();
			if(className.indexOf("cn.picclife.")!=-1 && className.indexOf("cn.picclife.mwx.manager.util.LogUtil")>-1){
				return msg + " class:[" + className 
						+ "] thread:[" + ThreadLocalContext.get().getThreadUUID() 
						+ "] ip:[" + ThreadLocalContext.get().getIp()
						+ "] project:[" + ThreadLocalContext.get().getProject()
						+ "] function:[" + ThreadLocalContext.get().getFunction()
						+ "]";
			}
		}
		return "";
	}
	
	
}
